Workspace

Packages

library(psych)
library(broom)
library(lme4)
library(knitr)
library(kableExtra)
library(plyr)
library(tidyverse)

Data

This week, our data are going to (continue to) come from the German Socioeconomic Panel Study (GSOEP). The GSOEP is a longitudinal study of adults in German housesholds. The study has a broad range of variables, but for our purposes we’re just going to use personality ratings, life events, age, gender, and general life satisfaction from 2005 to 2015. We’ll use life satisfaction from 2005 this week, but keep the other years for future use when we do time-varying moderators. We’ll use life events similarly to how we did for logistic regression, except this time as a moderator variable.

We need to extend our codebook. To create it, go to https://data.soep.de/soep-core# and use the search feature to find the variables you need or https://data.soep.de/soep-long/topics/ where you can scroll through topics (this may be easier for finding the personality variables). Use your codebook from last week, and add the additional variables.

Each year has several different files. Thankfully, for our purposes, we just need one file for each year. The first part of that file name indexes which wave it is. Waves are labeled a (1985) to bf (2015). Once the waves hit z, they start over at “ba”. The second piece of the filename indexes which type of file it is. We need the “p” files, which stand for person. So, for instance, 2005 is “vp.sav”.

There are different ways to load it in, but I would recommend using some form of loop, which should do the following:
1. read in the file for a specific year (e.g. using haven::read_sav()). 2. pull the variables from the codebook from that year (e.g. using select()). - NOTE: you should pull certain variables, like the person and household IDs for every year.
3. rename those variables in wide format.
4. add a column to the data for that year that indexes what year the observation is.
5. merge the data from that year with previous years.

For help with this, see https://emoriebeck.github.io/R-tutorials/purrr/. I’ll give you a purrr solution later in the week.

Once you’ve got the codebook, we should be ready to go.

# wd <- "https://github.com/emoriebeck/R-tutorials/blob/master/RA_Files/Week_7_Growth_Models_II"
wd <- "~/Documents/Github/R-tutorials/RA_Files/Week_7_Growth_Models_II"
# load your codebook 
# destfile <- "Codebook_EDB.xlsx"
# curl::curl_download(sprintf("%s/Codebook_EDB.xlsx?raw=true", wd), destfile)
# codebook <- readxl::read_excel(destfile) %>%
codebook <- readxl::read_excel(sprintf("%s/Codebook_EDB.xlsx", wd)) %>%
  mutate(Item = stringr::str_to_lower(Item))
# data_path <- "https://github.com/emoriebeck/R-tutorials/blob/master/RA_Files/Week_5_Logistic_Regression"
data_path <- "~/Documents/Github/R-tutorials/RA_Files/Week_5_Logistic_Regression"

all.old.cols <- (codebook %>% filter(class == "proc" & Year == 0))$Item
all.new.cols <- (codebook %>% filter(class == "proc" & Year == "0"))$new_name

# create short function to read in separate files for each wave
read_fun <- function(file, year){
  print(year)
  old.names <- (codebook %>% filter(Year == year))$Item
  new.names <- (codebook %>% filter(Year == year))$new_name
  # z <- read_csv(url(sprintf("%s/data/%sp.csv?raw=true", data_path, file))) %>%
  z <- read.csv(sprintf("%s/data/%sp.csv", data_path, file)) %>%
    select(one_of(all.old.cols), one_of(old.names)) %>%
    setNames(c(all.new.cols, new.names)) 
}

# you need letters, not numbers to index different data files. 
# but years will be more useful to index your codebook, so we'll 
# put both in our starting data frame. I've filled out this part. 
# Now you just need to figure out how use that to load the files 
# and get the correct variables (one's that repeat year to year)
dat <- tibble(
  Year = as.character(seq(2005, 2015,1)),
  file = c(letters[22:26], paste("b", letters[1:6], sep = ""))) %>%
  mutate(data = map2(file, Year, read_fun)) %>%
  unnest(data)
## [1] "2005"
## [1] "2006"
## [1] "2007"
## [1] "2008"
## [1] "2009"
## [1] "2010"
## [1] "2011"
## [1] "2012"
## [1] "2013"
## [1] "2014"
## [1] "2015"

Descriptives

Because our data are now longitudinal, we need to split our descriptives by year. Try doing this using the describeBy() in the psych package.

# run the descriptives and check variable ranges
describeBy(dat, dat$Year)
## 
##  Descriptive statistics by group 
## group: 2005
##                vars     n       mean         sd  median    trimmed
## Year*             1 10451    2005.00       0.00    2005    2005.00
## file*             2 10451        NaN         NA      NA        NaN
## PROC_SID          3 10451 3006396.71 2420592.24 2727001 2737008.54
## PROC_household    4 10451  297467.55  245527.78  273139  270013.72
## Dem_DOB           5 10451    1957.45      17.53    1958    1957.78
## Dem_Sex           6 10451       1.52       0.50       2       1.53
## BF_C1             7 10451       6.12       1.19       6       6.33
## BF_E1             8 10451       5.45       1.42       6       5.62
## BF_A1             9 10451       2.90       1.70       3       2.76
## BF_O1            10 10451       4.52       1.53       5       4.60
## BF_N1            11 10451       4.67       1.72       5       4.78
## BF_A2            12 10451       5.48       1.40       6       5.66
## BF_C2            13 10451       2.22       1.55       2       1.96
## BF_E2            14 10451       5.05       1.50       5       5.18
## BF_O2            15 10451       4.09       1.88       4       4.14
## BF_N2            16 10451       3.67       1.76       4       3.66
## BF_C3            17 10451       5.71       1.29       6       5.90
## BF_E3            18 10451       4.08       1.68       4       4.12
## BF_A3            19 10451       5.75       1.20       6       5.90
## BF_O3            20 10451       4.77       1.60       5       4.89
## BF_N3            21 10451       4.51       1.57       5       4.58
## LE_ChldBrth      22 10451      -1.93       0.45      -2      -2.00
## LE_ChldMvOut     23 10451      -1.93       0.46      -2      -2.00
## LE_Divorce       24 10451      -1.98       0.21      -2      -2.00
## LE_DadDied       25 10451      -1.97       0.31      -2      -2.00
## LE_Married       26 10451      -1.95       0.37      -2      -2.00
## LE_MomDied       27 10451      -1.97       0.30      -2      -2.00
## LE_MoveIn        28 10451      -1.95       0.40      -2      -2.00
## LE_PartDied      29 10451      -1.99       0.20      -2      -2.00
## LE_SepPart       30 10451      -1.95       0.38      -2      -2.00
## Psych_LifeSat    31 10451       6.92       1.89       7       7.11
## LE_NewPart       32     0        NaN         NA      NA        NaN
##                       mad  min     max   range  skew kurtosis       se
## Year*                0.00 2005    2005       0   NaN      NaN     0.00
## file*                  NA  Inf    -Inf    -Inf    NA       NA       NA
## PROC_SID       3246593.03  901 8263202 8262301  0.74    -0.35 23677.87
## PROC_household  340195.91   94  824984  824890  0.70    -0.41  2401.72
## Dem_DOB             20.76 1909    1988      79 -0.15    -0.80     0.17
## Dem_Sex              0.00    1       2       1 -0.10    -1.99     0.00
## BF_C1                1.48   -1       7       8 -2.45     9.39     0.01
## BF_E1                1.48   -1       7       8 -1.08     1.71     0.01
## BF_A1                1.48   -1       7       8  0.50    -0.65     0.02
## BF_O1                1.48   -1       7       8 -0.60     0.62     0.02
## BF_N1                1.48   -1       7       8 -0.48    -0.33     0.02
## BF_A2                1.48   -1       7       8 -1.23     2.20     0.01
## BF_C2                1.48   -1       7       8  1.16     0.66     0.02
## BF_E2                1.48   -1       7       8 -0.74     0.59     0.01
## BF_O2                1.48   -1       7       8 -0.24    -0.72     0.02
## BF_N2                1.48   -1       7       8  0.07    -0.80     0.02
## BF_C3                1.48   -1       7       8 -1.87     5.92     0.01
## BF_E3                1.48   -1       7       8 -0.24    -0.53     0.02
## BF_A3                1.48   -1       7       8 -1.48     4.22     0.01
## BF_O3                1.48   -1       7       8 -0.62     0.28     0.02
## BF_N3                1.48   -1       7       8 -0.48     0.04     0.02
## LE_ChldBrth          0.00   -2       1       3  6.30    37.67     0.00
## LE_ChldMvOut         0.00   -2       1       3  6.23    36.82     0.00
## LE_Divorce           0.00   -2       1       3 13.93   192.16     0.00
## LE_DadDied           0.00   -2       1       3  9.46    87.48     0.00
## LE_Married           0.00   -2       1       3  7.79    58.73     0.00
## LE_MomDied           0.00   -2       1       3  9.87    95.48     0.00
## LE_MoveIn            0.00   -2       1       3  7.23    50.30     0.00
## LE_PartDied          0.00   -2       1       3 14.50   208.25     0.00
## LE_SepPart           0.00   -2       1       3  7.67    56.85     0.00
## Psych_LifeSat        1.48   -1      10      11 -1.04     1.38     0.02
## LE_NewPart             NA  Inf    -Inf    -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2006
##                vars     n       mean         sd  median    trimmed
## Year*             1 11085    2006.00       0.00    2006    2006.00
## file*             2 11085        NaN         NA      NA        NaN
## PROC_SID          3 11085 3059412.03 2281556.03 2849801 2811416.13
## PROC_household    4 11085  303086.61  231649.53  285170  277923.72
## Dem_DOB           5 11085    1957.39      17.34    1958    1957.63
## Dem_Sex           6 11085       1.53       0.50       2       1.53
## BF_C1             7     0        NaN         NA      NA        NaN
## BF_E1             8     0        NaN         NA      NA        NaN
## BF_A1             9     0        NaN         NA      NA        NaN
## BF_O1            10     0        NaN         NA      NA        NaN
## BF_N1            11     0        NaN         NA      NA        NaN
## BF_A2            12     0        NaN         NA      NA        NaN
## BF_C2            13     0        NaN         NA      NA        NaN
## BF_E2            14     0        NaN         NA      NA        NaN
## BF_O2            15     0        NaN         NA      NA        NaN
## BF_N2            16     0        NaN         NA      NA        NaN
## BF_C3            17     0        NaN         NA      NA        NaN
## BF_E3            18     0        NaN         NA      NA        NaN
## BF_A3            19     0        NaN         NA      NA        NaN
## BF_O3            20     0        NaN         NA      NA        NaN
## BF_N3            21     0        NaN         NA      NA        NaN
## LE_ChldBrth      22 11085      -1.91       0.50      -2      -2.00
## LE_ChldMvOut     23 11085      -1.90       0.53      -2      -2.00
## LE_Divorce       24 11085      -1.98       0.23      -2      -2.00
## LE_DadDied       25 11085      -1.97       0.31      -2      -2.00
## LE_Married       26 11085      -1.95       0.37      -2      -2.00
## LE_MomDied       27 11085      -1.96       0.33      -2      -2.00
## LE_MoveIn        28 11085      -1.94       0.43      -2      -2.00
## LE_PartDied      29 11085      -1.99       0.20      -2      -2.00
## LE_SepPart       30 11085      -1.95       0.38      -2      -2.00
## Psych_LifeSat    31 11085       6.91       1.85       7       7.08
## LE_NewPart       32     0        NaN         NA      NA        NaN
##                       mad  min     max   range  skew kurtosis       se
## Year*                0.00 2006    2006       0   NaN      NaN     0.00
## file*                  NA  Inf    -Inf    -Inf    NA       NA       NA
## PROC_SID       2637099.14  901 8268502 8267601  0.73    -0.07 21670.22
## PROC_household  324072.64   94  824984  824890  0.69    -0.14  2200.21
## Dem_DOB             19.27 1909    1989      80 -0.12    -0.82     0.16
## Dem_Sex              0.00    1       2       1 -0.10    -1.99     0.00
## BF_C1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## LE_ChldBrth          0.00   -2       1       3  5.65    29.88     0.00
## LE_ChldMvOut         0.00   -2       1       3  5.32    26.34     0.01
## LE_Divorce           0.00   -2       1       3 12.74   160.42     0.00
## LE_DadDied           0.00   -2       1       3  9.45    87.37     0.00
## LE_Married           0.00   -2       1       3  7.94    60.99     0.00
## LE_MomDied           0.00   -2       1       3  8.96    78.34     0.00
## LE_MoveIn            0.00   -2       1       3  6.66    42.39     0.00
## LE_PartDied          0.00   -2       1       3 14.94   221.19     0.00
## LE_SepPart           0.00   -2       1       3  7.61    55.91     0.00
## Psych_LifeSat        1.48   -1      10      11 -1.03     1.63     0.02
## LE_NewPart             NA  Inf    -Inf    -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2007
##                vars     n       mean         sd  median    trimmed
## Year*             1 10438    2007.00       0.00    2007    2007.00
## file*             2 10438        NaN         NA      NA        NaN
## PROC_SID          3 10438 3053902.85 2303829.10 2829602 2803303.50
## PROC_household    4 10438  302841.40  234249.72  283339  277502.91
## Dem_DOB           5 10438    1958.09      17.41    1959    1958.30
## Dem_Sex           6 10438       1.53       0.50       2       1.53
## BF_C1             7     0        NaN         NA      NA        NaN
## BF_E1             8     0        NaN         NA      NA        NaN
## BF_A1             9     0        NaN         NA      NA        NaN
## BF_O1            10     0        NaN         NA      NA        NaN
## BF_N1            11     0        NaN         NA      NA        NaN
## BF_A2            12     0        NaN         NA      NA        NaN
## BF_C2            13     0        NaN         NA      NA        NaN
## BF_E2            14     0        NaN         NA      NA        NaN
## BF_O2            15     0        NaN         NA      NA        NaN
## BF_N2            16     0        NaN         NA      NA        NaN
## BF_C3            17     0        NaN         NA      NA        NaN
## BF_E3            18     0        NaN         NA      NA        NaN
## BF_A3            19     0        NaN         NA      NA        NaN
## BF_O3            20     0        NaN         NA      NA        NaN
## BF_N3            21     0        NaN         NA      NA        NaN
## LE_ChldBrth      22 10438      -1.93       0.44      -2      -2.00
## LE_ChldMvOut     23 10438      -1.91       0.52      -2      -2.00
## LE_Divorce       24 10438      -1.98       0.22      -2      -2.00
## LE_DadDied       25 10438      -1.97       0.30      -2      -2.00
## LE_Married       26 10438      -1.95       0.40      -2      -2.00
## LE_MomDied       27 10438      -1.97       0.30      -2      -2.00
## LE_MoveIn        28 10438      -1.92       0.47      -2      -2.00
## LE_PartDied      29 10438      -1.99       0.18      -2      -2.00
## LE_SepPart       30 10438      -1.95       0.39      -2      -2.00
## Psych_LifeSat    31 10438       6.93       1.84       7       7.11
## LE_NewPart       32     0        NaN         NA      NA        NaN
##                       mad  min     max   range  skew kurtosis       se
## Year*                0.00 2007    2007       0   NaN      NaN     0.00
## file*                  NA  Inf    -Inf    -Inf    NA       NA       NA
## PROC_SID       2770608.01  901 8271402 8270501  0.73    -0.13 22549.74
## PROC_household  329309.18   94  824984  824890  0.68    -0.21  2292.82
## Dem_DOB             19.27 1909    1989      80 -0.11    -0.83     0.17
## Dem_Sex              0.00    1       2       1 -0.10    -1.99     0.00
## BF_C1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## LE_ChldBrth          0.00   -2       1       3  6.48    40.01     0.00
## LE_ChldMvOut         0.00   -2       1       3  5.43    27.44     0.01
## LE_Divorce           0.00   -2       1       3 13.67   184.75     0.00
## LE_DadDied           0.00   -2       1       3  9.63    90.75     0.00
## LE_Married           0.00   -2       1       3  7.29    51.13     0.00
## LE_MomDied           0.00   -2       1       3  9.77    93.46     0.00
## LE_MoveIn            0.00   -2       1       3  6.05    34.56     0.00
## LE_PartDied          0.00   -2       1       3 16.94   284.89     0.00
## LE_SepPart           0.00   -2       1       3  7.53    54.65     0.00
## Psych_LifeSat        1.48   -1      10      11 -1.06     1.57     0.02
## LE_NewPart             NA  Inf    -Inf    -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2008
##                vars    n       mean         sd  median    trimmed
## Year*             1 9826    2008.00       0.00    2008    2008.00
## file*             2 9826        NaN         NA      NA        NaN
## PROC_SID          3 9826 3054938.00 2305363.46 2829602 2804337.97
## PROC_household    4 9826  302745.32  234444.13  283347  277365.25
## Dem_DOB           5 9826    1958.60      17.53    1959    1958.74
## Dem_Sex           6 9826       1.52       0.50       2       1.53
## BF_C1             7    0        NaN         NA      NA        NaN
## BF_E1             8    0        NaN         NA      NA        NaN
## BF_A1             9    0        NaN         NA      NA        NaN
## BF_O1            10    0        NaN         NA      NA        NaN
## BF_N1            11    0        NaN         NA      NA        NaN
## BF_A2            12    0        NaN         NA      NA        NaN
## BF_C2            13    0        NaN         NA      NA        NaN
## BF_E2            14    0        NaN         NA      NA        NaN
## BF_O2            15    0        NaN         NA      NA        NaN
## BF_N2            16    0        NaN         NA      NA        NaN
## BF_C3            17    0        NaN         NA      NA        NaN
## BF_E3            18    0        NaN         NA      NA        NaN
## BF_A3            19    0        NaN         NA      NA        NaN
## BF_O3            20    0        NaN         NA      NA        NaN
## BF_N3            21    0        NaN         NA      NA        NaN
## LE_ChldBrth      22 9826      -1.93       0.44      -2      -2.00
## LE_ChldMvOut     23 9826      -1.92       0.47      -2      -2.00
## LE_Divorce       24 9826      -1.99       0.20      -2      -2.00
## LE_DadDied       25 9826      -1.97       0.30      -2      -2.00
## LE_Married       26 9826      -1.96       0.36      -2      -2.00
## LE_MomDied       27 9826      -1.97       0.30      -2      -2.00
## LE_MoveIn        28 9826      -1.95       0.39      -2      -2.00
## LE_PartDied      29 9826      -1.99       0.21      -2      -2.00
## LE_SepPart       30 9826      -1.95       0.39      -2      -2.00
## Psych_LifeSat    31 9826       6.98       1.79       7       7.14
## LE_NewPart       32    0        NaN         NA      NA        NaN
##                       mad  min     max   range  skew kurtosis       se
## Year*                0.00 2008    2008       0   NaN      NaN     0.00
## file*                  NA  Inf    -Inf    -Inf    NA       NA       NA
## PROC_SID       2783729.02  901 8276202 8275301  0.73    -0.14 23256.86
## PROC_household  329567.15   94  824984  824890  0.67    -0.22  2365.11
## Dem_DOB             19.27 1909    1990      81 -0.07    -0.84     0.18
## Dem_Sex              0.00    1       2       1 -0.09    -1.99     0.01
## BF_C1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N1                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N2                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_C3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_E3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_A3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_O3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## BF_N3                  NA  Inf    -Inf    -Inf    NA       NA       NA
## LE_ChldBrth          0.00   -2       1       3  6.54    40.72     0.00
## LE_ChldMvOut         0.00   -2       1       3  6.00    34.01     0.00
## LE_Divorce           0.00   -2       1       3 14.51   208.57     0.00
## LE_DadDied           0.00   -2       1       3  9.71    92.28     0.00
## LE_Married           0.00   -2       1       3  7.99    61.85     0.00
## LE_MomDied           0.00   -2       1       3  9.97    97.34     0.00
## LE_MoveIn            0.00   -2       1       3  7.43    53.15     0.00
## LE_PartDied          0.00   -2       1       3 14.05   195.50     0.00
## LE_SepPart           0.00   -2       1       3  7.40    52.81     0.00
## Psych_LifeSat        1.48   -1      10      11 -1.03     1.50     0.02
## LE_NewPart             NA  Inf    -Inf    -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2009
##                vars     n       mean         sd  median    trimmed
## Year*             1 10327    2009.00       0.00    2009    2009.00
## file*             2 10327        NaN         NA      NA        NaN
## PROC_SID          3 10327 3746217.99 2832106.78 2981502 3564937.58
## PROC_household    4 10327  372040.85  286840.94  298352  353663.26
## Dem_DOB           5 10327    1959.03      17.62    1959    1959.10
## Dem_Sex           6 10327       1.52       0.50       2       1.53
## BF_C1             7 10327       6.09       1.21       6       6.31
## BF_E1             8 10327       5.39       1.44       6       5.56
## BF_A1             9 10327       2.99       1.66       3       2.88
## BF_O1            10 10327       4.46       1.52       4       4.52
## BF_N1            11 10327       4.32       1.72       4       4.34
## BF_A2            12 10327       5.33       1.45       6       5.51
## BF_C2            13 10327       2.39       1.60       2       2.17
## BF_E2            14 10327       4.93       1.55       5       5.04
## BF_O2            15 10327       3.96       1.90       4       3.97
## BF_N2            16 10327       3.57       1.70       4       3.54
## BF_C3            17 10327       5.69       1.30       6       5.87
## BF_E3            18 10327       4.05       1.65       4       4.09
## BF_A3            19 10327       5.65       1.24       6       5.80
## BF_O3            20 10327       4.65       1.61       5       4.74
## BF_N3            21 10327       4.44       1.55       5       4.52
## LE_ChldBrth      22 10327      -1.92       0.49      -2      -2.00
## LE_ChldMvOut     23 10327      -1.93       0.45      -2      -2.00
## LE_Divorce       24 10327      -1.99       0.20      -2      -2.00
## LE_DadDied       25 10327      -1.97       0.29      -2      -2.00
## LE_Married       26 10327      -1.95       0.37      -2      -2.00
## LE_MomDied       27 10327      -1.97       0.32      -2      -2.00
## LE_MoveIn        28 10327      -1.94       0.43      -2      -2.00
## LE_PartDied      29 10327      -1.98       0.23      -2      -2.00
## LE_SepPart       30 10327      -1.95       0.38      -2      -2.00
## Psych_LifeSat    31 10327       6.96       1.81       7       7.12
## LE_NewPart       32     0        NaN         NA      NA        NaN
##                       mad  min     max   range  skew kurtosis       se
## Year*                0.00 2009    2009       0   NaN      NaN     0.00
## file*                  NA  Inf    -Inf    -Inf    NA       NA       NA
## PROC_SID       3127989.48  901 8999901 8999000  0.57    -0.87 27869.07
## PROC_household  320260.87   94  899992  899898  0.53    -0.89  2822.63
## Dem_DOB             19.27 1909    1992      83 -0.04    -0.85     0.17
## Dem_Sex              0.00    1       2       1 -0.10    -1.99     0.00
## BF_C1                1.48   -1       7       8 -2.37     8.75     0.01
## BF_E1                1.48   -1       7       8 -1.00     1.42     0.01
## BF_A1                1.48   -1       7       8  0.45    -0.59     0.02
## BF_O1                1.48   -1       7       8 -0.48     0.46     0.01
## BF_N1                1.48   -1       7       8 -0.23    -0.62     0.02
## BF_A2                1.48   -1       7       8 -1.13     1.76     0.01
## BF_C2                1.48   -1       7       8  0.97     0.28     0.02
## BF_E2                1.48   -1       7       8 -0.70     0.59     0.02
## BF_O2                1.48   -1       7       8 -0.12    -0.82     0.02
## BF_N2                1.48   -1       7       8  0.13    -0.69     0.02
## BF_C3                1.48   -1       7       8 -1.80     5.45     0.01
## BF_E3                1.48   -1       7       8 -0.26    -0.38     0.02
## BF_A3                1.48   -1       7       8 -1.52     4.45     0.01
## BF_O3                1.48   -1       7       8 -0.48     0.00     0.02
## BF_N3                1.48   -1       7       8 -0.46     0.01     0.02
## LE_ChldBrth          0.00   -2       1       3  5.82    31.90     0.00
## LE_ChldMvOut         0.00   -2       1       3  6.29    37.51     0.00
## LE_Divorce           0.00   -2       1       3 14.88   219.46     0.00
## LE_DadDied           0.00   -2       1       3 10.06    99.30     0.00
## LE_Married           0.00   -2       1       3  7.92    60.78     0.00
## LE_MomDied           0.00   -2       1       3  9.11    81.05     0.00
## LE_MoveIn            0.00   -2       1       3  6.66    42.38     0.00
## LE_PartDied          0.00   -2       1       3 13.11   170.01     0.00
## LE_SepPart           0.00   -2       1       3  7.62    56.11     0.00
## Psych_LifeSat        1.48   -1      10      11 -0.97     1.37     0.02
## LE_NewPart             NA  Inf    -Inf    -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2010
##                vars     n       mean         sd  median    trimmed
## Year*             1 13230    2010.00       0.00    2010    2010.00
## file*             2 13230        NaN         NA      NA        NaN
## PROC_SID          3 13230 8687797.90 8118552.20 5076254 8161911.97
## PROC_household    4 13230  867077.29  813872.45  507857  814715.84
## Dem_DOB           5 13230    1379.80     895.97    1948    1477.01
## Dem_Sex           6 13230      -0.40       3.00       1      -0.13
## BF_C1             7     0        NaN         NA      NA        NaN
## BF_E1             8     0        NaN         NA      NA        NaN
## BF_A1             9     0        NaN         NA      NA        NaN
## BF_O1            10     0        NaN         NA      NA        NaN
## BF_N1            11     0        NaN         NA      NA        NaN
## BF_A2            12     0        NaN         NA      NA        NaN
## BF_C2            13     0        NaN         NA      NA        NaN
## BF_E2            14     0        NaN         NA      NA        NaN
## BF_O2            15     0        NaN         NA      NA        NaN
## BF_N2            16     0        NaN         NA      NA        NaN
## BF_C3            17     0        NaN         NA      NA        NaN
## BF_E3            18     0        NaN         NA      NA        NaN
## BF_A3            19     0        NaN         NA      NA        NaN
## BF_O3            20     0        NaN         NA      NA        NaN
## BF_N3            21     0        NaN         NA      NA        NaN
## LE_ChldBrth      22 13230      -2.84       1.45      -2      -2.73
## LE_ChldMvOut     23 13230      -2.83       1.46      -2      -2.73
## LE_Divorce       24 13230      -2.87       1.39      -2      -2.73
## LE_DadDied       25 13230      -2.86       1.41      -2      -2.73
## LE_Married       26 13230      -2.85       1.42      -2      -2.73
## LE_MomDied       27 13230      -2.86       1.41      -2      -2.73
## LE_MoveIn        28 13230      -2.84       1.45      -2      -2.73
## LE_PartDied      29 13230      -2.87       1.39      -2      -2.73
## LE_SepPart       30 13230      -2.86       1.42      -2      -2.73
## Psych_LifeSat    31 13230       7.24       1.76       8       7.40
## LE_NewPart       32     0        NaN         NA      NA        NaN
##                       mad  min      max    range  skew kurtosis       se
## Year*                0.00 2010     2010        0   NaN      NaN     0.00
## file*                  NA  Inf     -Inf     -Inf    NA       NA       NA
## PROC_SID       5537436.87  901 21536602 21535701  0.66    -1.29 70582.76
## PROC_household  549392.26   94  2153664  2153570  0.65    -1.29  7075.81
## Dem_DOB             34.10   -5     1992     1997 -0.90    -1.19     7.79
## Dem_Sex              1.48   -5        2        7 -0.84    -1.21     0.03
## BF_C1                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E1                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A1                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O1                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N1                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A2                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_C2                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E2                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O2                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N2                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_C3                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E3                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A3                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O3                  NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N3                  NA  Inf     -Inf     -Inf    NA       NA       NA
## LE_ChldBrth          0.00   -5        1        6 -0.55    -0.66     0.01
## LE_ChldMvOut         0.00   -5        1        6 -0.50    -0.61     0.01
## LE_Divorce           0.00   -5        1        6 -0.79    -1.02     0.01
## LE_DadDied           0.00   -5        1        6 -0.72    -0.91     0.01
## LE_Married           0.00   -5        1        6 -0.65    -0.80     0.01
## LE_MomDied           0.00   -5        1        6 -0.72    -0.91     0.01
## LE_MoveIn            0.00   -5        1        6 -0.55    -0.67     0.01
## LE_PartDied          0.00   -5        1        6 -0.79    -1.01     0.01
## LE_SepPart           0.00   -5        1        6 -0.67    -0.83     0.01
## Psych_LifeSat        1.48   -1       10       11 -1.08     1.71     0.02
## LE_NewPart             NA  Inf     -Inf     -Inf    NA       NA       NA
## -------------------------------------------------------- 
## group: 2011
##                vars     n        mean          sd  median     trimmed
## Year*             1 14347     2011.00        0.00    2011     2011.00
## file*             2 14347         NaN          NA      NA         NaN
## PROC_SID          3 14347 12737750.79 11308717.31 7235502 12050013.39
## PROC_household    4 14347  1272299.99  1132701.85  723347  1203922.14
## Dem_DOB           5 14347     1428.98      872.61    1950     1538.29
## Dem_Sex           6 14347        1.55        0.50       2        1.56
## BF_C1             7     0         NaN          NA      NA         NaN
## BF_E1             8     0         NaN          NA      NA         NaN
## BF_A1             9     0         NaN          NA      NA         NaN
## BF_O1            10     0         NaN          NA      NA         NaN
## BF_N1            11     0         NaN          NA      NA         NaN
## BF_A2            12     0         NaN          NA      NA         NaN
## BF_C2            13     0         NaN          NA      NA         NaN
## BF_E2            14     0         NaN          NA      NA         NaN
## BF_O2            15     0         NaN          NA      NA         NaN
## BF_N2            16     0         NaN          NA      NA         NaN
## BF_C3            17     0         NaN          NA      NA         NaN
## BF_E3            18     0         NaN          NA      NA         NaN
## BF_A3            19     0         NaN          NA      NA         NaN
## BF_O3            20     0         NaN          NA      NA         NaN
## BF_N3            21     0         NaN          NA      NA         NaN
## LE_ChldBrth      22 14347       -2.00        0.93      -2       -2.00
## LE_ChldMvOut     23 14347       -2.08        0.80      -2       -2.00
## LE_Divorce       24 14347       -2.13        0.68      -2       -2.00
## LE_DadDied       25 14347       -2.11        0.72      -2       -2.00
## LE_Married       26 14347       -2.10        0.75      -2       -2.00
## LE_MomDied       27 14347       -2.11        0.72      -2       -2.00
## LE_MoveIn        28 14347       -2.10        0.76      -2       -2.00
## LE_PartDied      29 14347       -2.13        0.67      -2       -2.00
## LE_SepPart       30 14347       -2.10        0.74      -2       -2.00
## Psych_LifeSat    31 14347        6.11        3.86       7        7.00
## LE_NewPart       32 14347       -2.07        0.82      -2       -2.00
##                        mad  min      max    range  skew kurtosis       se
## Year*                 0.00 2011     2011        0   NaN      NaN     0.00
## file*                   NA  Inf     -Inf     -Inf    NA       NA       NA
## PROC_SID       10362634.18  901 30979502 30978601  0.39    -1.45 94413.22
## PROC_household  1044902.38   94  3097950  3097856  0.39    -1.45  9456.60
## Dem_DOB              29.65   -5     1993     1998 -1.03    -0.93     7.29
## Dem_Sex               0.00    1        2        1 -0.18    -1.97     0.00
## BF_C1                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E1                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A1                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O1                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N1                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A2                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_C2                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E2                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O2                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N2                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_C3                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_E3                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_A3                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_O3                   NA  Inf     -Inf     -Inf    NA       NA       NA
## BF_N3                   NA  Inf     -Inf     -Inf    NA       NA       NA
## LE_ChldBrth           0.00   -5        1        6 -0.04     7.49     0.01
## LE_ChldMvOut          0.00   -5        1        6 -1.04    10.73     0.01
## LE_Divorce            0.00   -5        1        6 -3.13    14.48     0.01
## LE_DadDied            0.00   -5        1        6 -2.20    13.11     0.01
## LE_Married            0.00   -5        1        6 -1.70    12.21     0.01
## LE_MomDied            0.00   -5        1        6 -2.22    13.15     0.01
## LE_MoveIn             0.00   -5        1        6 -1.65    12.10     0.01
## LE_PartDied           0.00   -5        1        6 -3.30    14.70     0.01
## LE_SepPart            0.00   -5        1        6 -1.85    12.49     0.01
## Psych_LifeSat         1.48   -5       10       15 -2.04     3.32     0.03
## LE_NewPart            0.00   -5        1        6 -0.86    10.27     0.01
## -------------------------------------------------------- 
## group: 2012
##                vars     n        mean          sd  median     trimmed
## Year*             1 13996     2012.00        0.00    2012     2012.00
## file*             2 13996         NaN          NA      NA         NaN
## PROC_SID          3 13996 14264024.93 11848265.32 8250354 13898035.71
## PROC_household    4 13996  1425277.75  1185855.89  824507  1389517.26
## Dem_DOB           5 13996     1449.04      862.37    1951     1563.27
## Dem_Sex           6 13996        0.25        2.63       1        0.69
## BF_C1             7     0         NaN          NA      NA         NaN
## BF_E1             8     0         NaN          NA      NA         NaN
## BF_A1             9     0         NaN          NA      NA         NaN
## BF_O1            10     0         NaN          NA      NA         NaN
## BF_N1            11     0         NaN          NA      NA         NaN
## BF_A2            12     0         NaN          NA      NA         NaN
## BF_C2            13     0         NaN          NA      NA         NaN
## BF_E2            14     0         NaN          NA      NA         NaN
## BF_O2            15     0         NaN          NA      NA         NaN
## BF_N2            16     0         NaN          NA      NA         NaN
## BF_C3            17     0         NaN          NA      NA         NaN
## BF_E3            18     0         NaN          NA      NA         NaN
## BF_A3            19     0         NaN          NA      NA         NaN
## BF_O3            20     0         NaN          NA      NA         NaN
## BF_N3            21     0         NaN          NA      NA         NaN
## LE_ChldBrth      22 13996       -1.93        0.45      -2       -2.00
## LE_ChldMvOut     23 13996       -1.92        0.48      -2       -2.00
## LE_Divorce       24 13996       -1.98        0.22      -2       -2.00
## LE_DadDied       25 13996       -1.97        0.30      -2       -2.00
## LE_Married       26 13996       -1.94        0.42      -2       -2.00
## LE_MomDied       27 13996       -1.97        0.30      -2       -2.00
## LE_MoveIn        28 13996       -1.95        0.37      -2       -2.00
## LE_PartDied      29 13996       -1.99        0.17      -2       -2.00
## LE_SepPart       30 13996       -1.95        0.40      -2       -2.00
## Psych_LifeSat    31 13996      218.73      211.42     200      204.37
## LE_NewPart       32 13996       -1.91        0.50      -2       -2.00
##                        mad  min      max    range  skew kurtosis        se
## Year*                 0.00 2012     2012        0   NaN      NaN      0.00
## file*                   NA  Inf     -Inf     -Inf    NA       NA        NA
## PROC_SID       12205433.34  901 35008702 35007801  0.22    -1.59 100150.43
## PROC_household  1219978.17   94  3143391  3143297  0.21    -1.59  10023.74
## Dem_DOB              29.65   -5     1994     1999 -1.09    -0.81      7.29
## Dem_Sex               1.48   -5        2        7 -1.42     0.19      0.02
## BF_C1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## LE_ChldBrth           0.00   -2        1        3  6.35    38.35      0.00
## LE_ChldMvOut          0.00   -2        1        3  5.90    32.85      0.00
## LE_Divorce            0.00   -2        1        3 13.28   174.42      0.00
## LE_DadDied            0.00   -2        1        3  9.67    91.52      0.00
## LE_Married            0.00   -2        1        3  6.83    44.64      0.00
## LE_MomDied            0.00   -2        1        3  9.81    94.26      0.00
## LE_MoveIn             0.00   -2        1        3  7.82    59.21      0.00
## LE_PartDied           0.00   -2        1        3 17.55   305.98      0.00
## LE_SepPart            0.00   -2        1        3  7.26    50.77      0.00
## Psych_LifeSat       299.49   -3      980      983  0.25    -1.36      1.79
## LE_NewPart            0.00   -2        1        3  5.62    29.58      0.00
## -------------------------------------------------------- 
## group: 2013
##                vars     n        mean          sd   median     trimmed
## Year*             1 15544     2013.00        0.00     2013     2013.00
## file*             2 15544         NaN          NA       NA         NaN
## PROC_SID          3 15544 16994593.68 12707407.51 20219202 17089462.50
## PROC_household    4 15544  1698114.62  1270928.67  2021768  1709304.13
## Dem_DOB           5 15544     1204.85      956.41     1943     1258.13
## Dem_Sex           6 15544       -0.96        3.20        1       -0.83
## BF_C1             7 15544        1.84        5.48        5        2.05
## BF_E1             8 15544        1.48        5.23        4        1.60
## BF_A1             9 15544       -0.07        4.11        1       -0.17
## BF_O1            10 15544        0.93        4.83        4        0.97
## BF_N1            11 15544        0.65        4.66        2        0.62
## BF_A2            12 15544        1.40        5.18        4        1.50
## BF_C2            13 15544       -0.44        3.82        1       -0.58
## BF_E2            14 15544        1.23        5.06        4        1.29
## BF_O2            15 15544        0.68        4.73        2        0.63
## BF_N2            16 15544        0.30        4.40        2        0.22
## BF_C3            17 15544        1.61        5.31        5        1.77
## BF_E3            18 15544        0.59        4.60        2        0.57
## BF_A3            19 15544        1.63        5.32        5        1.79
## BF_O3            20 15544        1.03        4.92        4        1.05
## BF_N3            21 15544        0.89        4.80        3        0.92
## LE_ChldBrth      22 15544       -2.43        1.19       -2       -2.22
## LE_ChldMvOut     23 15544       -2.41        1.22       -2       -2.22
## LE_Divorce       24 15544       -2.47        1.12       -2       -2.22
## LE_DadDied       25 15544       -2.45        1.15       -2       -2.22
## LE_Married       26 15544       -2.42        1.20       -2       -2.22
## LE_MomDied       27 15544       -2.45        1.15       -2       -2.22
## LE_MoveIn        28 15544       -2.44        1.16       -2       -2.22
## LE_PartDied      29 15544       -2.47        1.12       -2       -2.22
## LE_SepPart       30 15544       -2.43        1.18       -2       -2.22
## Psych_LifeSat    31 15544        7.30        1.77        8        7.46
## LE_NewPart       32 15544       -2.39        1.24       -2       -2.22
##                        mad  min      max    range  skew kurtosis        se
## Year*                 0.00 2013     2013        0   NaN      NaN      0.00
## file*                   NA  Inf     -Inf     -Inf    NA       NA        NA
## PROC_SID       17929453.19  901 35022002 35021101 -0.06    -1.68 101923.79
## PROC_household  1792455.99   94  3343277  3343183 -0.06    -1.68  10193.89
## Dem_DOB              53.37   -5     1995     2000 -0.47    -1.77      7.67
## Dem_Sex               1.48   -5        2        7 -0.44    -1.74      0.03
## BF_C1                 2.97   -5        7       12 -0.41    -1.77      0.04
## BF_E1                 4.45   -5        7       12 -0.36    -1.75      0.04
## BF_A1                 5.93   -5        7       12 -0.15    -1.58      0.03
## BF_O1                 2.97   -5        7       12 -0.31    -1.72      0.04
## BF_N1                 5.93   -5        7       12 -0.23    -1.67      0.04
## BF_A2                 4.45   -5        7       12 -0.35    -1.75      0.04
## BF_C2                 4.45   -5        7       12 -0.11    -1.47      0.03
## BF_E2                 4.45   -5        7       12 -0.33    -1.74      0.04
## BF_O2                 5.93   -5        7       12 -0.20    -1.67      0.04
## BF_N2                 4.45   -5        7       12 -0.20    -1.64      0.04
## BF_C3                 2.97   -5        7       12 -0.39    -1.76      0.04
## BF_E3                 5.93   -5        7       12 -0.25    -1.69      0.04
## BF_A3                 2.97   -5        7       12 -0.40    -1.76      0.04
## BF_O3                 2.97   -5        7       12 -0.30    -1.72      0.04
## BF_N3                 4.45   -5        7       12 -0.30    -1.72      0.04
## LE_ChldBrth           0.00   -5        1        6 -1.17     1.72      0.01
## LE_ChldMvOut          0.00   -5        1        6 -0.99     1.73      0.01
## LE_Divorce            0.00   -5        1        6 -1.67     1.55      0.01
## LE_DadDied            0.00   -5        1        6 -1.46     1.65      0.01
## LE_Married            0.00   -5        1        6 -1.10     1.73      0.01
## LE_MomDied            0.00   -5        1        6 -1.46     1.65      0.01
## LE_MoveIn             0.00   -5        1        6 -1.34     1.69      0.01
## LE_PartDied           0.00   -5        1        6 -1.71     1.53      0.01
## LE_SepPart            0.00   -5        1        6 -1.21     1.72      0.01
## Psych_LifeSat         1.48   -1       10       11 -1.12     1.93      0.01
## LE_NewPart            0.00   -5        1        6 -0.86     1.71      0.01
## -------------------------------------------------------- 
## group: 2014
##                vars     n        mean          sd   median     trimmed
## Year*             1 13777     2014.00        0.00     2014     2014.00
## file*             2 13777         NaN          NA       NA         NaN
## PROC_SID          3 13777 16326819.90 12763111.56 20158602 16264090.54
## PROC_household    4 13777  1631250.64  1275101.57  2015750  1627050.99
## Dem_DOB           5 13777     1692.96      679.34     1962     1867.69
## Dem_Sex           6 13777        1.54        0.50        2        1.55
## BF_C1             7     0         NaN          NA       NA         NaN
## BF_E1             8     0         NaN          NA       NA         NaN
## BF_A1             9     0         NaN          NA       NA         NaN
## BF_O1            10     0         NaN          NA       NA         NaN
## BF_N1            11     0         NaN          NA       NA         NaN
## BF_A2            12     0         NaN          NA       NA         NaN
## BF_C2            13     0         NaN          NA       NA         NaN
## BF_E2            14     0         NaN          NA       NA         NaN
## BF_O2            15     0         NaN          NA       NA         NaN
## BF_N2            16     0         NaN          NA       NA         NaN
## BF_C3            17     0         NaN          NA       NA         NaN
## BF_E3            18     0         NaN          NA       NA         NaN
## BF_A3            19     0         NaN          NA       NA         NaN
## BF_O3            20     0         NaN          NA       NA         NaN
## BF_N3            21     0         NaN          NA       NA         NaN
## LE_ChldBrth      22 13777       -1.94        0.42       -2       -2.00
## LE_ChldMvOut     23 13777       -1.92        0.49       -2       -2.00
## LE_Divorce       24 13777       -1.99        0.21       -2       -2.00
## LE_DadDied       25 13777       -1.97        0.32       -2       -2.00
## LE_Married       26 13777       -1.94        0.43       -2       -2.00
## LE_MomDied       27 13777       -1.97        0.31       -2       -2.00
## LE_MoveIn        28 13777       -1.95        0.36       -2       -2.00
## LE_PartDied      29 13777       -1.99        0.18       -2       -2.00
## LE_SepPart       30 13777       -1.95        0.36       -2       -2.00
## Psych_LifeSat    31 13777        7.23        1.78        8        7.40
## LE_NewPart       32 13777       -1.91        0.52       -2       -2.00
##                        mad  min      max    range  skew kurtosis        se
## Year*                 0.00 2014     2014        0   NaN      NaN      0.00
## file*                   NA  Inf     -Inf     -Inf    NA       NA        NA
## PROC_SID       17986163.38  901 35032702 35031801  0.03    -1.70 108737.47
## PROC_household  1795950.48   94  3343277  3343183  0.03    -1.70  10863.44
## Dem_DOB              23.72   -5     1996     2001 -2.10     2.40      5.79
## Dem_Sex               0.00    1        2        1 -0.15    -1.98      0.00
## BF_C1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## LE_ChldBrth           0.00   -2        1        3  6.94    46.23      0.00
## LE_ChldMvOut          0.00   -2        1        3  5.82    31.86      0.00
## LE_Divorce            0.00   -2        1        3 14.23   200.60      0.00
## LE_DadDied            0.00   -2        1        3  9.12    81.11      0.00
## LE_Married            0.00   -2        1        3  6.67    42.52      0.00
## LE_MomDied            0.00   -2        1        3  9.56    89.36      0.00
## LE_MoveIn             0.00   -2        1        3  7.97    61.56      0.00
## LE_PartDied           0.00   -2        1        3 16.34   265.10      0.00
## LE_SepPart            0.00   -2        1        3  7.97    61.56      0.00
## Psych_LifeSat         1.48   -1       10       11 -1.17     2.12      0.02
## LE_NewPart            0.00   -2        1        3  5.41    27.29      0.00
## -------------------------------------------------------- 
## group: 2015
##                vars     n        mean          sd   median     trimmed
## Year*             1 13606     2015.00        0.00     2015     2015.00
## file*             2 13606         NaN          NA       NA         NaN
## PROC_SID          3 13606 17266633.00 12967650.82 20248652 17290122.17
## PROC_household    4 13606  1726650.51  1295611.58  2024600  1731291.47
## Dem_DOB           5 13606     1841.06      481.62     1966     1964.70
## Dem_Sex           6 13606        1.12        1.67        2        1.51
## BF_C1             7     0         NaN          NA       NA         NaN
## BF_E1             8     0         NaN          NA       NA         NaN
## BF_A1             9     0         NaN          NA       NA         NaN
## BF_O1            10     0         NaN          NA       NA         NaN
## BF_N1            11     0         NaN          NA       NA         NaN
## BF_A2            12     0         NaN          NA       NA         NaN
## BF_C2            13     0         NaN          NA       NA         NaN
## BF_E2            14     0         NaN          NA       NA         NaN
## BF_O2            15     0         NaN          NA       NA         NaN
## BF_N2            16     0         NaN          NA       NA         NaN
## BF_C3            17     0         NaN          NA       NA         NaN
## BF_E3            18     0         NaN          NA       NA         NaN
## BF_A3            19     0         NaN          NA       NA         NaN
## BF_O3            20     0         NaN          NA       NA         NaN
## BF_N3            21     0         NaN          NA       NA         NaN
## LE_ChldBrth      22 13606       -2.13        0.85       -2       -2.00
## LE_ChldMvOut     23 13606       -2.11        0.90       -2       -2.00
## LE_Divorce       24 13606       -2.18        0.76       -2       -2.00
## LE_DadDied       25 13606       -2.16        0.80       -2       -2.00
## LE_Married       26 13606       -2.13        0.85       -2       -2.00
## LE_MomDied       27 13606       -2.16        0.80       -2       -2.00
## LE_MoveIn        28 13606       -2.15        0.82       -2       -2.00
## LE_PartDied      29 13606       -2.18        0.76       -2       -2.00
## LE_SepPart       30 13606       -2.15        0.83       -2       -2.00
## Psych_LifeSat    31 13606        7.38        1.77        8        7.56
## LE_NewPart       32 13606       -2.09        0.93       -2       -2.00
##                        mad  min      max    range  skew kurtosis        se
## Year*                 0.00 2015     2015        0   NaN      NaN      0.00
## file*                   NA  Inf     -Inf     -Inf    NA       NA        NA
## PROC_SID       18155623.08  901 35031602 35030701 -0.05    -1.67 111172.17
## PROC_household  1812236.84   94  3499900  3499806 -0.06    -1.67  11107.33
## Dem_DOB              20.76   -5     1997     2002 -3.57    10.74      4.13
## Dem_Sex               0.00   -5        2        7 -3.08     8.60      0.01
## BF_C1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N1                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N2                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_C3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_E3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_A3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_O3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## BF_N3                   NA  Inf     -Inf     -Inf    NA       NA        NA
## LE_ChldBrth           0.00   -5        1        6 -1.48     8.64      0.01
## LE_ChldMvOut          0.00   -5        1        6 -0.94     7.65      0.01
## LE_Divorce            0.00   -5        1        6 -2.86    10.27      0.01
## LE_DadDied            0.00   -5        1        6 -2.19     9.60      0.01
## LE_Married            0.00   -5        1        6 -1.47     8.62      0.01
## LE_MomDied            0.00   -5        1        6 -2.21     9.63      0.01
## LE_MoveIn             0.00   -5        1        6 -1.94     9.30      0.01
## LE_PartDied           0.00   -5        1        6 -2.99    10.37      0.01
## LE_SepPart            0.00   -5        1        6 -1.79     9.09      0.01
## Psych_LifeSat         1.48   -1       10       11 -1.26     2.42      0.02
## LE_NewPart            0.00   -5        1        6 -0.71     7.13      0.01

Check Missings

How are missings coded in this data set? Do we need to make any changes to how they are coded?

# You should have noted some variables that needed "scrubbed" (changed to missing)
# change those to NA using your preferred method
dat <- dat %>% mutate_all(funs(mapvalues(., seq(-1,-7,-1), rep(NA,7), warn_missing = F)))

Recode Variables

# You should have your keys. Reverse code the items that need reverse coded. 
keys     <- codebook$rev_code[codebook$rev_code == -1]
items    <- codebook$new_name[codebook$rev_code == -1]
dat[,items] <- reverse.code(keys, dat[,items], mini = 1, maxi = 7)

# I'm going to give you this chunk because apparently some people don't know what year they were born
dat <- dat %>% 
  group_by(PROC_SID) %>% 
  mutate(
    Dem_DOB = max(Dem_DOB, na.rm = T),
    Dem_DOB = ifelse(is.infinite(Dem_DOB) == T, NA, Dem_DOB),
    Dem_Sex = max(Dem_Sex, na.rm = T),
    Dem_Sex = ifelse(is.infinite(Dem_Sex) == T, NA, Dem_Sex)
  )

Create New Variables

For these data, we need to create an age variable. There isn’t one in the data set.v

# create an age variable by subtracting the date of birth from 2005 
# change gender to a factor 
dat <- dat %>% 
  mutate(age = 2005 - Dem_DOB,
         gender = factor(Dem_Sex, levels = c(1,2), labels = c("Male", "Female")))

# create a composite "parent died" variable
dat <- dat %>%
    group_by(PROC_SID) %>%
    mutate(LE_ParDied = max(LE_MomDied,LE_DadDied, na.rm = T),
           LE_ParDied = ifelse(is.nan(LE_ParDied) == T, NA, LE_ParDied)) 

Create composites

For these data, we have lots of items, so we don’t just want to create composites for the Big 5, we also want to create composites for the facets of each of the Big 5. Use the methods we learned before to do so.

Personality

pers_dat <- dat %>%
  gather(key = item, value = value, BF_A1:BF_O3, na.rm = T) %>%
  separate(item, c("trait", "item"), -1) %>%
  group_by(trait, PROC_SID, PROC_household, Year, Dem_DOB, age, Dem_Sex, gender) %>%
  summarize(value = mean(value, na.rm = T)) %>%
  spread(key = trait, value = value) %>% 
  ungroup() %>%
  mutate(wave = as.numeric(Year) - 2005)

Life Events

We want to code if someone experienced a life event anywhere within the study period. Experiment with different ways of doing this. Note that we want to figure out if a participant EVER responded with a 1 to any of our life event variables.

le_dat <- dat %>% select(-contains("BF")) %>%
  gather(key = le, value = le_value, contains("LE_")) %>%
  group_by(PROC_SID, age, gender, le) %>%
  summarize(le_value = ifelse(any(le_value == 1), 1, 0),
            le_value = ifelse(is.na(le_value), 0, le_value)) %>%
  ungroup() %>%
  spread(key = le, value = le_value)

Merge the files

dat_final <- pers_dat %>% 
  full_join(le_dat) %>% 
  full_join(dat %>% filter(Year == 2005) %>% select(PROC_SID, Psych_LifeSat)) %>%
  mutate(wave = as.numeric(Year) - 2005)

Adding Predictors in MLM/HLM

Last week, we talked about building simple longitudinal models in R using MLM/HLM. This week, we’re going to extend the “simple” MLM growth curve model to include additional predictors. Depending on the type of predictor, you can add these predictors at level 1 or level 2. Figuring out which level your covariates are at is very important. Part of this will have to do with whether you expect level 1 and level 2 variables to interact.

To demonstrate what I mean by this, we can start by considering the case where we want to add a covariate like age at level 1, where we want to partial out how age influences the model, but not to see how personality changes over time as a function of age.

The simple growth model has the following form: Level 1: \(Y_{ij} = \beta_{0j} + \beta_{1j}*time_{ij} + \varepsilon_{ij}\)
Level 2:
Random Intercept: \(\beta_{0j} = \gamma_{00} + U_{0j}\)
Random Slope: \(\beta_{1j} = \gamma_{10} + U_{1j}\)

Additional Level 1 Covariate

When we add age as a covariate, it has the following form:
Level 1: \(Y_{ij} = \beta_{0j} + \beta_{1j}*time_{ij} + \beta_{2j}*age_{ij} + \varepsilon_{ij}\)
Level 2:
Intercept: \(\beta_{0j} = \gamma_{00} + U_{0j}\) (random intercept)
Time Slope: \(\beta_{1j} = \gamma_{10} + U_{1j}\) (random slope)
Age Slope: \(\beta_{2j} = \gamma_{20}\) (no random slope)

Note that this does add an additional level 2 equation, but we don’t add an addiitonal random slope. How does this affect our model? One of the easiest ways to see this is to “sub in” the level 2 models into the level 1 equation, which gives us:
\(Y_{ij} = \gamma_{00} + U_{0j} + (\gamma_{10} + U_{1j})*time_{ij} + (\gamma_{20})*age_{ij} + \varepsilon{ij}\)

So in this case, we are just adding one addition term (a fixed effect age term), which we would interpret the same as we would if we added an age variable in multiple regression.

Additional Level 2 Covariate

Sometimes, we are interested in covariates that we expect to interact with our level 1 covariates, but we have no reason to think that we should

Level 1: \(Y_{ij} = \beta_{0j} + \beta_{1j}*time_{ij} + \varepsilon_{ij}\)
Level 2:
Intercept: \(\beta_{0j} = \gamma_{00} + \gamma_{01}*life\_sat\_w1_{j} + U_{0j}\) (random intercept)
Time Slope: \(\beta_{1j} = \gamma_{10} + \gamma_{11}*life\_sat\_w1_{j} + U_{1j}\) (random slope)

Which combines to:
\(Y_{ij} = \gamma_{00} + \gamma{11}*life\_sat\_w1_{j} + U_{0j} + (\gamma_{10} + \gamma{11}*life\_sat\_w1_{j} + U_{1j})*time_{ij} + \varepsilon{ij}\)
\(Y_{ij} = \gamma_{00} + \gamma{11}*life\_sat\_w1_{j} + \gamma_{10}*time_{ij} + \gamma{11}*life\_sat\_w1_{j}*time_{ij} + U_{0j} + U_{1j}*time + \varepsilon_{ij}\)

Simple Growth Curve Model

But first, we’ll start by looking at a spaghetti plot of the personality data.

In R

(unconditional_model <- unique(dat_final %>% select(PROC_SID:BF_O, Psych_LifeSat, wave)) %>%
  gather(key = Trait, value = value, BF_A:BF_O, na.rm = T) %>%
  group_by(Trait, PROC_SID) %>%
  mutate(n = n(), Year = as.numeric(Year)) %>% filter(n > 1) %>%
  group_by(Trait) %>%
  nest() %>%
  mutate(model = map(data, ~lmer(value ~ 1 + (1|PROC_SID), data = .)),
         ICC = map_dbl(model, reghelper::ICC),
         summary = map(model, ~print(summary(.)))))
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ 1 + (1 | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 47367.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -6.0281 -0.4899  0.0211  0.5302  3.7581 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PROC_SID (Intercept) 0.1592   0.3990  
##  Residual             0.3759   0.6131  
## Number of obs: 22093, groups:  PROC_SID, 8563
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 4.732968   0.005996   789.4
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ 1 + (1 | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 52943.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.9661 -0.4748 -0.0339  0.4069  4.3265 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PROC_SID (Intercept) 0.2271   0.4766  
##  Residual             0.4733   0.6880  
## Number of obs: 22057, groups:  PROC_SID, 8552
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 4.056923   0.006963   582.7
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ 1 + (1 | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 55839
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.1119 -0.5818 -0.0509  0.6079  3.4235 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PROC_SID (Intercept) 0.2276   0.4771  
##  Residual             0.5565   0.7460  
## Number of obs: 22076, groups:  PROC_SID, 8558
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 4.584514   0.007232   633.9
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ 1 + (1 | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 72501.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.5972 -0.5295 -0.0141  0.6243  3.4435 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PROC_SID (Intercept) 0.9606   0.9801  
##  Residual             0.9541   0.9768  
## Number of obs: 22080, groups:  PROC_SID, 8560
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  4.05188    0.01252   323.7
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ 1 + (1 | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 64453.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.7680 -0.5165  0.0257  0.5374  3.7288 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  PROC_SID (Intercept) 0.8265   0.9091  
##  Residual             0.6079   0.7797  
## Number of obs: 22076, groups:  PROC_SID, 8559
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  4.47130    0.01118     400
# Thus, we see that we have due cause to use an HLM -- the ICC of the unconditional models was `r round((unconditional_model %>% filter(Trait == "BF_A"))$ICC,2)` (A), `r round((unconditional_model %>% filter(Trait == "BF_C"))$ICC,2)` (C), `r round((unconditional_model %>% filter(Trait == "BF_E"))$ICC,2)` (E), `r round((unconditional_model %>% filter(Trait == "BF_N"))$ICC,2)` (N), and `r round((unconditional_model %>% filter(Trait == "BF_O"))$ICC,2)` (O).  

Like last week, we can break down this output into its component parts:

Fixed Effects

Start by looking at the part that says “Fixed effects”. This will be most familiar to you and easy to interpret. These are simply the population level (average) effects. In this case we have:

In this case, for the fixed effects, we only have an intercept because this is the unconditional model. The intercept here is just the average of the outcome variable.

Random Effects

The random effects are your individual differences. This section will give you variance estimates of the level 1 and 2 (random effect) variances.

Because this is the unconditional model, we have only a random intercept variance, which tells us how much people differ in average levels of the outcome. Then, we would typically look at the ICC to see if we are capturing a fair amount of the variability in the outcome by estimating something separately for each person.

The estimates in the “Residual” section are the Level 1 residuals. So this would be found by extracting the residuals of the model (e.g. using the resid() function) and finding their variance. Ideally this value is small, which indicates that most people don’t differ much from the model.

Scaled Residuals

The scaled residuals can tell you about how your level 1 residuals are distributed. Remember that we want these to be normally distributed (in an ideal world). You can check these out and see if the estimates seem symmetrical. This isn’t a section of primary importance, but it’s good to check out.

Conditional Models: Adding Predictors

Let’s see if we can better predict participants’ change in sensation seeking over time by adding covariates.

Predictor Continuous Categorical
Time Invariant Life Satisfaction in 2005 Life Event Group

Time Invariant Predictors

Time Invariant Predictors: Continuous

As a reminder, the model we plan to fit is as follows:
Level 1: \(Y_{ij} = \beta_{0j} + \beta_{1j}*time_{ij} + \varepsilon_{ij}\)
Level 2:
Intercept: \(\beta_{0j} = \gamma_{00} + \gamma_{01}*life\_sat\_w1_{j} + U_{0j}\) (random intercept)
Time Slope: \(\beta_{1j} = \gamma_{10} + \gamma_{11}*life\_sat\_w1_{j} + U_{1j}\) (random slope)

But we’ll also need to test whether we need the random slope.

Continuous Example - Life Satisfaction

# no random slope
unconditional_model <- unconditional_model %>% 
  mutate(mod1 = map(data, ~lmer(value ~ wave + Psych_LifeSat + wave*Psych_LifeSat + 
                                  (1|PROC_SID), data = .)),
         summary1 = map(mod1, ~print(summary(.))))

Now, let’s add a random slope and compare the models. A couple of these will fail to converge, but we’ll get to how to deal with that later.

# random slope and intercept
unconditional_model <- unconditional_model %>% 
  mutate(mod2 = map(data, ~lmer(value ~ wave + Psych_LifeSat + wave*Psych_LifeSat + 
                                  (Year | PROC_SID), data = .)),
         summary2 = map(mod2, ~print(summary(.))))
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 42925.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.9706 -0.5173  0.0185  0.5274  3.7962 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 4.245e-01 0.6515277      
##           Year        2.729e-07 0.0005224 -1.00
##  Residual             3.769e-01 0.6139485      
## Number of obs: 20020, groups:  PROC_SID, 7529
## 
## Fixed effects:
##                     Estimate Std. Error t value
## (Intercept)         4.531765   0.032253  140.51
## wave                0.006612   0.005748    1.15
## Psych_LifeSat       0.031108   0.004445    7.00
## wave:Psych_LifeSat -0.001503   0.000790   -1.90
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.605              
## Psych_LifSt -0.969  0.586       
## wv:Psych_LS  0.588 -0.969 -0.606
## convergence code: 0
## Model failed to converge with max|grad| = 1.47439 (tol = 0.002, component 1)
## Model is nearly unidentifiable: very large eigenvalue
##  - Rescale variables?
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
## 
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 47867.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.9157 -0.5001 -0.0344  0.4004  4.3180 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 5.378e-01 0.7333207      
##           Year        3.551e-07 0.0005959 -1.00
##  Residual             4.775e-01 0.6910110      
## Number of obs: 19990, groups:  PROC_SID, 7521
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)         3.7948774  0.0367534  103.25
## wave               -0.0012968  0.0064868   -0.20
## Psych_LifeSat       0.0325977  0.0050649    6.44
## wave:Psych_LifeSat  0.0009043  0.0008913    1.01
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.598              
## Psych_LifSt -0.969  0.579       
## wv:Psych_LS  0.580 -0.969 -0.598
## convergence code: 0
## Model failed to converge with max|grad| = 2.02804 (tol = 0.002, component 1)
## Model is nearly unidentifiable: very large eigenvalue
##  - Rescale variables?
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
## 
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 50653.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.0778 -0.5595 -0.0230  0.5773  3.4507 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 6.298e-01 0.7936125      
##           Year        3.998e-07 0.0006323 -1.00
##  Residual             5.593e-01 0.7478441      
## Number of obs: 20005, groups:  PROC_SID, 7525
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)         4.2805461  0.0390846  109.52
## wave                0.0130628  0.0070022    1.87
## Psych_LifeSat       0.0430005  0.0053864    7.98
## wave:Psych_LifeSat -0.0016047  0.0009623   -1.67
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.609              
## Psych_LifSt -0.969  0.589       
## wv:Psych_LS  0.591 -0.969 -0.609
## convergence code: 0
## Model failed to converge with max|grad| = 1.80725 (tol = 0.002, component 1)
## Model is nearly unidentifiable: very large eigenvalue
##  - Rescale variables?
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
## 
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 64962.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8704 -0.5723 -0.0047  0.5708  3.5171 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 1.071e+00 1.0347277      
##           Year        8.870e-07 0.0009418 -0.97
##  Residual             9.475e-01 0.9733743      
## Number of obs: 20009, groups:  PROC_SID, 7527
## 
## Fixed effects:
##                     Estimate Std. Error t value
## (Intercept)         5.480993   0.060318   90.87
## wave               -0.069851   0.009187   -7.60
## Psych_LifeSat      -0.185958   0.008314  -22.37
## wave:Psych_LifeSat  0.005297   0.001263    4.20
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.511              
## Psych_LifSt -0.969  0.495       
## wv:Psych_LS  0.496 -0.969 -0.512
## convergence code: 0
## unable to evaluate scaled gradient
## Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
## 
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 58230.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.6640 -0.5257  0.0279  0.5474  3.7185 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 6.905e-01 0.8309479      
##           Year        7.424e-07 0.0008616 -1.00
##  Residual             6.111e-01 0.7817529      
## Number of obs: 20005, groups:  PROC_SID, 7526
## 
## Fixed effects:
##                      Estimate Std. Error t value
## (Intercept)         3.8504678  0.0537350   71.66
## wave               -0.0004291  0.0074036   -0.06
## Psych_LifeSat       0.0928792  0.0074064   12.54
## wave:Psych_LifeSat -0.0013481  0.0010172   -1.33
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.459              
## Psych_LifSt -0.969  0.445       
## wv:Psych_LS  0.446 -0.969 -0.460
## convergence code: 0
## unable to evaluate scaled gradient
## Model failed to converge: degenerate  Hessian with 1 negative eigenvalues

As before, let’s unpack the results of one of the models (Agreeableness and Child Birth):

unconditional_model$summary2[[1]]
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + Psych_LifeSat + wave * Psych_LifeSat + (Year |  
##     PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 42925.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.9706 -0.5173  0.0185  0.5274  3.7962 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 4.245e-01 0.6515277      
##           Year        2.729e-07 0.0005224 -1.00
##  Residual             3.769e-01 0.6139485      
## Number of obs: 20020, groups:  PROC_SID, 7529
## 
## Fixed effects:
##                     Estimate Std. Error t value
## (Intercept)         4.531765   0.032253  140.51
## wave                0.006612   0.005748    1.15
## Psych_LifeSat       0.031108   0.004445    7.00
## wave:Psych_LifeSat -0.001503   0.000790   -1.90
## 
## Correlation of Fixed Effects:
##             (Intr) wave   Psy_LS
## wave        -0.605              
## Psych_LifSt -0.969  0.586       
## wv:Psych_LS  0.588 -0.969 -0.606
## convergence code: 0
## Model failed to converge with max|grad| = 1.47439 (tol = 0.002, component 1)
## Model is nearly unidentifiable: very large eigenvalue
##  - Rescale variables?
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?

Fixed Effects

Start by looking at the part that says “Fixed effects”. This will be most familiar to you and easy to interpret. These are simply the population level (average) effects. In this case we have:

wave: The average change in personality for each new wave of data was .007.
wave:Psych_LifeSat: Agreeableness doesn’t appear to change as a function of both wave and life satisfaction.

Random Effects

The random effects are your individual differences. This section will give you variance estimates of the level 1 and 2 (random effect) variances.

The estimates in the “Groups” PROC_SID are the level 2 random effects. In other words, if we were to extract the level 1 residuals or the level 2 random effects (\(r_{0j}\) and \(r_{1j}\)) and find their variance (old school style, like you learned in intro stats), these would be your variance estimates. The variance of the random intercepts is \(\tau_{00}^2\) (0 = intercept), while the variance of the random slopes is \(\tau_{11}^2\) (1 = slope). This also gives us a standard deviation, which if you remember, tells us something about the precision of the estimate.

The estimates in the “Residual” section are the Level 1 residuals. So this would be found by extracting the residuals of the model (e.g. using the resid() function) and finding their variance. Ideally this value is small, which indicates that most people don’t differ much from the model.

The only column we haven’t discussed in the “Corr” column. In our model, we (implicitly) specified that we not only wanted to model the level 2 variances but also the correlation between level 2 variables, which in this case, means the correlation between random slopes and intercepts. A positive correlation would mean that people with higher scores at baseline tended to show increases in personality over time, while a negative correlation would mean that people with lower scores at baseline tended to show increases. Sometimes we might want to remove this correlation, but that’s a topic for a later time. In this case, we see that the variables are almost perfectly correlated. That is likely a scaling issue that led to the non-convergence. There are ways to fix this (e.g. if we grand mean centered Psych_LifeSat. I encourage you to rerun the above with a centered life satisfaction variable if you’re curious. For now, this document will be long enough).

Scaled Residuals

The scaled residuals can tell you about how your level 1 residuals are distributed. Remember that we want these to be normally distributed (in an ideal world). You can check these out and see if the estimates seem symmetrical. This isn’t a section of primary importance, but it’s good to check out.

Correlation of Fixed Effects:

(I think this is the corrected correlation between wave and the outcome?)

Plots

We will plot these very similar to how we plotted moderated effects before. The only difference will be that we need to add the argument re.form = NA to the predict function.

Look at the graphs, what do you think this tells us about the relationship between personality, personality change, and life satisfaction?

fixed.frame <- unique(dat_final %>% select(PROC_SID, Psych_LifeSat)) %>%
  summarise(mean = mean(Psych_LifeSat, na.rm = T), 
            sd = sd(Psych_LifeSat, na.rm = T))

pred_fun <- function(fit){
  crossing(
      wave = seq(0,8,1), 
      Psych_LifeSat = c(fixed.frame$mean-fixed.frame$sd,
                     fixed.frame$mean,
                     fixed.frame$mean+fixed.frame$sd)
      ) %>%
    mutate(pred = predict(fit, newdata = ., re.form = NA))
}

unconditional_model <- unconditional_model %>%
  mutate(pred1 = map(mod1, pred_fun), 
         pred2 = map(mod2, pred_fun))

unconditional_model %>% unnest(pred1) %>%
  mutate(group = mapvalues(Psych_LifeSat, unique(Psych_LifeSat), c("-1SD", "0SD", "1SD"))) %>%
  ggplot(aes(x = wave, y = pred, color = group)) +
  geom_line() + 
  facet_wrap(~Trait, nrow = 2) +
  theme_classic()

Tabling Results

The function below is the same one from before. I just included it again for reference.

table_fun <- function(model){
  fixed <- broom::tidy(model) %>% filter(group == "fixed") %>%
    select(term, estimate) 
  ## add random effects ##
  rand <- VarCorr(model)[[1]]
  if(nrow(rand) > 1){
  rand <- rand[1:nrow(rand), 1:nrow(rand)]
  }
  colnames(rand)[colnames(rand) == "(Intercept)"] <- "Intercept"
  rownames(rand)[rownames(rand) == "(Intercept)"] <- "Intercept"
  vars <- rownames(rand)
  rand[upper.tri(rand)] <- NA
  rand <- data.frame(rand) %>% mutate(var1 = rownames(.)) %>%
    gather(key = var2, value = estimate, -var1, na.rm = T) %>%
    mutate(var1 = mapvalues(var1, vars, 0:(length(vars)-1)),
           var2 = mapvalues(var2, unique(var2), 0:(length(vars)-1))) %>%
    filter(var1 == var2) %>%
    unite(var, var1, var2, sep = "") %>%
    mutate(var = sprintf("$\\tau_{%s}$", var))
  ## get confidence intervals ##
  CI <- data.frame(confint.merMod(model, method = "boot", nsim = 10, oldNames = F)) %>%
    mutate(term = rownames(.)) %>% setNames(c("lower", "upper", "term"))
  
  CI %>% filter(term == "sigma") %>%
    mutate(estimate = sigma(model),
           term = "$\\sigma^2$",
           type = "Residuals")
  
  ## Get ICC & R2 values ##
  R2 <- MuMIn::r.squaredGLMM(model)
  
  ## format the fixed effects
  fixed <- fixed %>% left_join(CI %>% filter(!grepl(".sig", term))) %>%
    mutate(type = "Fixed Parts", term = str_remove_all(term, "[()]"))
  
  rand <- rand %>%
    left_join(
      CI %>% filter(grepl("sd", term)) %>%
        mutate(lower = lower^2, upper = upper^2,
               var = mapvalues(term, unique(term), 0:(length(unique(term))-1)),
               var = sprintf("$\\tau_{%s%s}$", var, var)) %>% select(-term)) %>%
    mutate(type = "Random Parts") %>% rename(term = var)
  
  mod_terms <- tribble(
    ~term, ~estimate, ~type,
    # "ICC", ICC, "Model Terms",
    "$R^2_m$", R2[1], "Model Terms",
    "$R^2_c$", R2[2], "Model Terms"
  )
  
  tab <- fixed %>%
    full_join(rand) %>%
    mutate(CI = sprintf("[%.2f, %.2f]", lower, upper)) %>%
    select(-lower, -upper) %>%
    full_join(mod_terms) %>%
    mutate(estimate = sprintf("%.2f", estimate)) %>%
    dplyr::rename(b = estimate) %>%
    select(type, everything())
  return(tab)
}

We can use this function for the models in our table:

unconditional_model <- unconditional_model %>% mutate(l.tab2 = map(mod2, table_fun))

unconditional_model %>% unnest(l.tab2)

This function does most of the heavy lifting for us, but we will need to reorganize. With 5 traits, I usually do something like the following:

(tab <- unconditional_model %>% 
# unnest the table results
unnest(l.tab2) %>%
# remove the ICC
select(-ICC) %>%
# make the b and CI long for reshaping 
gather(key = est, value = value, b, CI, na.rm = T) %>%
# create a new variable joining together the type of term (b, CI) and trait
unite(tmp, Trait, est, sep = ".") %>%
# change to wide format
spread(key = tmp, value = value) %>%
# factor the rows to control rearrangement
mutate(type = factor(type, levels = c("Fixed Parts", "Random Parts", "Model Terms"))) %>% 
# rearrange the variables
arrange(type))

Then, we can use this with knitr::kable() and the kableExtra package to create a nicely formatted table output.

tab %>% 
  knitr::kable(., "html", booktabs = T, escape = F,
        # set the column names
        col.names = c("", "Term", rep(c("b", "CI"), times = 5)),
        # set column alignment
        align = c("l", "l", rep("c", 10))) %>%
  kable_styling(full_width = F) %>%
  # create floating header above
  add_header_above(c(" " = 2, "Agreeableness" = 2, "Conscientiousness" = 2, 
                    "Extraversion" = 2, "Neuroticism" = 2, "Openness" = 2))
Agreeableness
Conscientiousness
Extraversion
Neuroticism
Openness
Term b CI b CI b CI b CI b CI
Fixed Parts Intercept 4.53 [4.48, 4.59] 3.79 [3.73, 3.84] 4.28 [4.21, 4.35] 5.48 [5.39, 5.55] 3.85 [3.73, 3.89]
Fixed Parts Psych_LifeSat 0.03 [0.02, 0.04] 0.03 [0.03, 0.04] 0.04 [0.04, 0.05] -0.19 [-0.20, -0.17] 0.09 [0.09, 0.11]
Fixed Parts wave 0.01 [0.00, 0.02] -0.00 [-0.01, 0.01] 0.01 [0.01, 0.03] -0.07 [-0.08, -0.07] -0.00 [-0.01, 0.01]
Fixed Parts wave:Psych_LifeSat -0.00 [-0.00, -0.00] 0.00 [-0.00, 0.00] -0.00 [-0.00, -0.00] 0.01 [0.00, 0.01] -0.00 [-0.00, 0.00]
Random Parts \(\tau_{00}\) 0.42 [0.42, 0.43] 0.54 [0.53, 0.54] 0.63 [0.62, 0.64] 1.07 [1.20, 1.36] 0.69 [0.77, 0.81]
Random Parts \(\tau_{11}\) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.00 [0.00, 0.00]
Model Terms \(R^2_c\) 0.30 NA 0.31 NA 0.29 NA 0.51 NA 0.58 NA
Model Terms \(R^2_m\) 0.00 NA 0.01 NA 0.01 NA 0.05 NA 0.02 NA

Time Invariant Predictors: Categorical

Categorical Example - 2 level group

In the case of categorical moderators, it’s slightly easier to understand because the different levels at which thee may be different relationships among predictors and outcomes.

In the case of life events moderating personality change, the model we plan to fit is as follows:
Level 1: \(Y_{ij} = \beta_{0j} + \beta_{1j}*time_{ij} + \varepsilon_{ij}\)
Level 2:
Intercept: \(\beta_{0j} = \gamma_{00} + \gamma_{01}*life\_event_{j} + U_{0j}\) (random intercept)
Time Slope: \(\beta_{1j} = \gamma_{10} + \gamma_{11}*life\_event_w1_{j} + U_{1j}\) (random slope)

Where \(life\_event_{j}\) is a dummy coded variable that is coded 1 when someone experienced a life event between 2005 and 2015, and 0 otherwise.

And plot it.

And model it:

nested.mods <- dat_final %>%
  gather(key = Trait, value = value, BF_A:BF_O, na.rm = T) %>%
  gather(key = Event, value = le_value, contains("LE"), na.rm = T) %>%
  mutate(le_value = factor(le_value), Year = as.numeric(Year)) %>%
  group_by(Trait, Event, PROC_SID) %>%
  mutate(n = n()) %>% filter(n > 1) %>%
  filter(!is.na(value) & !is.na(le_value)) %>%
  group_by(Trait, Event) %>%
  nest() 

# no random slope
nested.mods <- nested.mods %>%
  mutate(mod1 = map(data, ~lmer(value ~ wave + le_value + wave:le_value + 
                                  (1|PROC_SID), data = .)),
         summary1 = map(mod1, ~summary(.)))
# add a random slope
nested.mods <- nested.mods %>%
  mutate(mod2 = map(data, ~lmer(value ~ wave + le_value + wave:le_value + 
                                  (Year|PROC_SID), data = .)),
         summary2 = map(mod2, ~summary(.)))

(nested.mods %>%
  mutate(comp = map2(mod1, mod2, anova)))$comp[[1]]

As before, let’s unpack the results of one of the models (Agreeableness and Child Birth):

nested.mods$summary2[[1]]
## Linear mixed model fit by REML ['lmerMod']
## Formula: value ~ wave + le_value + wave:le_value + (Year | PROC_SID)
##    Data: .
## 
## REML criterion at convergence: 47381.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.9907 -0.5136  0.0233  0.5264  3.7713 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  PROC_SID (Intercept) 4.231e-01 0.6504513      
##           Year        2.730e-07 0.0005225 -1.00
##  Residual             3.757e-01 0.6129192      
## Number of obs: 22093, groups:  PROC_SID, 8563
## 
## Fixed effects:
##                 Estimate Std. Error t value
## (Intercept)     4.743753   0.008301   571.4
## wave           -0.004116   0.001448    -2.8
## le_value1       0.030863   0.024441     1.3
## wave:le_value1  0.001642   0.004183     0.4
## 
## Correlation of Fixed Effects:
##             (Intr) wave   le_vl1
## wave        -0.639              
## le_value1   -0.340  0.217       
## wave:le_vl1  0.221 -0.346 -0.652
## convergence code: 0
## Model failed to converge with max|grad| = 1.37389 (tol = 0.002, component 1)
## Model is nearly unidentifiable: very large eigenvalue
##  - Rescale variables?
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?

Fixed Effects

Start by looking at the part that says “Fixed effects”. This will be most familiar to you and easy to interpret. These are simply the population level (average) effects. In this case we have:

wave: The average change in personality for each new wave of data was .007.
wave:le_value: People who experience a life event don’t change differently than those who didn’t.

Random Effects

The random effects are your individual differences. This section will give you variance estimates of the level 1 and 2 (random effect) variances.

These are the same as we discussed before for the continuous moderator. You’ll notice that these estimates differ in magnitude. That’s because they are basically the individual differences in mean level personality and personality change that can’t be accounted for by our predcitors.

Scaled Residuals

The scaled residuals can tell you about how your level 1 residuals are distributed. Remember that we want these to be normally distributed (in an ideal world). You can check these out and see if the estimates seem symmetrical. This isn’t a section of primary importance, but it’s good to check out.

Correlation of Fixed Effects:

(I think this is the corrected correlation between wave and the outcome?)

Plots

pred_fun <- function(fit){
  crossing(
      wave = seq(0,8,1), 
      le_value = factor(c(0,1))
      ) %>%
    mutate(pred = predict(fit, newdata = ., re.form = NA))
}

nested.mods <- nested.mods %>%
  mutate(pred1 = map(mod1, pred_fun), 
         pred2 = map(mod2, pred_fun))

nested.mods %>% unnest(pred1) %>%
  ggplot(aes(x = wave, y = pred, color = le_value)) +
  geom_line() + 
  facet_grid(Event~Trait) +
  theme_classic()

Tabling Results

nested.mods <- nested.mods %>% mutate(l.tab2 = map(mod2, table_fun))

nested.mods %>% unnest(l.tab2)

This function does most of the heavy lifting for us, but we will need to reorganize. With 5 traits, I usually do something like the following:

(tab <- nested.mods %>% 
# unnest the table results
unnest(l.tab2) %>%
# make the b and CI long for reshaping 
gather(key = est, value = value, b, CI, na.rm = T) %>%
# create a new variable joining together the type of term (b, CI) and trait
unite(tmp, Trait, est, sep = ".") %>%
# change to wide format
spread(key = tmp, value = value) %>%
# factor the rows to control rearrangement
mutate(type = factor(type, levels = c("Fixed Parts", "Random Parts", "Model Terms"))) %>% 
# rearrange the variables
arrange(type, term))

Then, we can use this with knitr::kable() and the kableExtra package to create a nicely formatted table output.

tab %>% 
  filter(type == "Fixed Parts") %>%
  knitr::kable(., "html", booktabs = T, escape = F,
        # set the column names
        col.names = c("", "Event", "Term", rep(c("b", "CI"), times = 5)),
        # set column alignment
        align = c("l", "l", rep("c", 10))) %>%
  kable_styling(full_width = F) %>%
  # create floating header above
  add_header_above(c(" " = 3, "Agreeableness" = 2, "Conscientiousness" = 2, 
                    "Extraversion" = 2, "Neuroticism" = 2, "Openness" = 2))
Agreeableness
Conscientiousness
Extraversion
Neuroticism
Openness
Event Term b CI b CI b CI b CI b CI
LE_ChldBrth Fixed Parts Intercept 4.74 [4.74, 4.76] 4.02 [4.00, 4.04] 4.58 [4.57, 4.60] 4.19 [4.16, 4.21] 4.50 [4.47, 4.51]
LE_ChldMvOut Fixed Parts Intercept 4.74 [4.72, 4.75] 4.05 [4.04, 4.07] 4.59 [4.58, 4.60] 4.16 [4.13, 4.19] 4.49 [4.47, 4.51]
LE_DadDied Fixed Parts Intercept 4.75 [4.75, 4.78] 4.03 [4.02, 4.05] 4.59 [4.57, 4.61] 4.16 [4.12, 4.22] 4.50 [4.48, 4.51]
LE_Divorce Fixed Parts Intercept 4.75 [4.73, 4.76] 4.03 [4.02, 4.05] 4.58 [4.58, 4.60] 4.16 [4.14, 4.19] 4.50 [4.49, 4.52]
LE_Married Fixed Parts Intercept 4.74 [4.73, 4.75] 4.01 [4.00, 4.03] 4.59 [4.57, 4.60] 4.18 [4.16, 4.20] 4.49 [4.48, 4.51]
LE_MomDied Fixed Parts Intercept 4.74 [4.73, 4.75] 4.04 [4.02, 4.06] 4.58 [4.57, 4.60] 4.16 [4.14, 4.19] 4.50 [4.49, 4.51]
LE_MoveIn Fixed Parts Intercept 4.75 [4.73, 4.76] 4.01 [4.01, 4.03] 4.58 [4.57, 4.60] 4.17 [4.13, 4.20] 4.49 [4.48, 4.51]
LE_NewPart Fixed Parts Intercept 4.75 [4.73, 4.76] 4.02 [4.01, 4.03] 4.58 [4.57, 4.60] 4.17 [4.16, 4.20] 4.49 [4.47, 4.51]
LE_ParDied Fixed Parts Intercept 4.74 [4.73, 4.76] 4.03 [4.02, 4.05] 4.59 [4.57, 4.60] 4.16 [4.13, 4.18] 4.49 [4.48, 4.54]
LE_PartDied Fixed Parts Intercept 4.75 [4.74, 4.76] 4.04 [4.03, 4.06] 4.58 [4.57, 4.60] 4.16 [4.15, 4.19] 4.51 [4.49, 4.53]
LE_SepPart Fixed Parts Intercept 4.75 [4.73, 4.77] 4.02 [4.00, 4.03] 4.59 [4.58, 4.60] 4.16 [4.12, 4.18] 4.49 [4.48, 4.50]
LE_ChldBrth Fixed Parts le_value1 0.03 [0.01, 0.07] 0.16 [0.10, 0.21] -0.01 [-0.08, 0.01] -0.15 [-0.21, -0.11] 0.01 [-0.06, 0.07]
LE_ChldMvOut Fixed Parts le_value1 0.05 [0.02, 0.10] -0.10 [-0.13, -0.07] -0.07 [-0.11, -0.04] 0.04 [-0.02, 0.13] 0.04 [0.01, 0.06]
LE_DadDied Fixed Parts le_value1 0.02 [-0.03, 0.07] 0.07 [0.03, 0.08] -0.09 [-0.13, -0.04] 0.05 [-0.07, 0.21] 0.03 [-0.01, 0.12]
LE_Divorce Fixed Parts le_value1 -0.02 [-0.13, 0.08] 0.03 [-0.02, 0.09] -0.13 [-0.20, -0.09] 0.14 [0.05, 0.28] 0.04 [-0.08, 0.15]
LE_Married Fixed Parts le_value1 0.07 [0.03, 0.14] 0.22 [0.18, 0.26] -0.07 [-0.14, -0.02] -0.11 [-0.15, -0.02] 0.13 [0.06, 0.19]
LE_MomDied Fixed Parts le_value1 0.06 [-0.01, 0.10] -0.01 [-0.07, 0.03] -0.03 [-0.10, 0.03] 0.07 [-0.03, 0.15] 0.03 [-0.03, 0.07]
LE_MoveIn Fixed Parts le_value1 0.02 [-0.02, 0.05] 0.24 [0.19, 0.28] -0.06 [-0.08, -0.02] 0.00 [-0.08, 0.05] 0.14 [0.05, 0.18]
LE_NewPart Fixed Parts le_value1 0.02 [-0.02, 0.06] 0.27 [0.22, 0.35] -0.11 [-0.16, -0.02] -0.08 [-0.16, 0.07] 0.24 [0.15, 0.34]
LE_ParDied Fixed Parts le_value1 0.05 [0.02, 0.06] 0.04 [0.01, 0.07] -0.06 [-0.08, -0.04] 0.05 [-0.10, 0.09] 0.04 [0.01, 0.10]
LE_PartDied Fixed Parts le_value1 -0.05 [-0.10, 0.02] -0.24 [-0.32, -0.15] 0.08 [0.01, 0.18] 0.25 [0.18, 0.40] -0.28 [-0.40, -0.17]
LE_SepPart Fixed Parts le_value1 0.00 [-0.03, 0.04] 0.17 [0.13, 0.25] -0.13 [-0.20, -0.10] 0.09 [0.02, 0.16] 0.13 [0.05, 0.16]
LE_ChldBrth Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.01] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.00]
LE_ChldMvOut Fixed Parts wave -0.00 [-0.01, 0.00] 0.00 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.00]
LE_DadDied Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.04, -0.03] -0.01 [-0.01, -0.00]
LE_Divorce Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.04, -0.03] -0.01 [-0.01, -0.01]
LE_Married Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [0.00, 0.01] -0.03 [-0.04, -0.03] -0.01 [-0.01, -0.01]
LE_MomDied Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.01] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.01]
LE_MoveIn Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.01]
LE_NewPart Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.04, -0.03] -0.01 [-0.01, -0.00]
LE_ParDied Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.03, -0.02] -0.01 [-0.01, -0.01]
LE_PartDied Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.01]
LE_SepPart Fixed Parts wave -0.00 [-0.01, -0.00] 0.01 [0.00, 0.01] 0.00 [-0.00, 0.00] -0.03 [-0.03, -0.03] -0.01 [-0.01, -0.01]
LE_ChldBrth Fixed Parts wave:le_value1 0.00 [-0.00, 0.01] -0.01 [-0.02, -0.00] -0.01 [-0.02, -0.00] 0.00 [-0.01, 0.01] 0.00 [-0.00, 0.01]
LE_ChldMvOut Fixed Parts wave:le_value1 -0.00 [-0.01, 0.01] 0.01 [0.00, 0.02] 0.00 [-0.00, 0.01] -0.00 [-0.02, 0.01] 0.00 [-0.00, 0.01]
LE_DadDied Fixed Parts wave:le_value1 -0.00 [-0.01, 0.00] 0.00 [-0.00, 0.01] 0.01 [-0.00, 0.02] 0.00 [-0.01, 0.01] -0.01 [-0.03, -0.00]
LE_Divorce Fixed Parts wave:le_value1 0.01 [-0.00, 0.02] -0.00 [-0.01, 0.01] 0.01 [0.00, 0.02] -0.01 [-0.02, 0.01] 0.01 [-0.00, 0.03]
LE_Married Fixed Parts wave:le_value1 0.00 [-0.00, 0.02] -0.01 [-0.01, 0.00] -0.00 [-0.01, 0.01] 0.01 [-0.00, 0.02] -0.00 [-0.01, 0.01]
LE_MomDied Fixed Parts wave:le_value1 -0.00 [-0.01, 0.01] -0.00 [-0.01, 0.01] 0.00 [-0.00, 0.01] -0.00 [-0.01, 0.01] 0.01 [0.00, 0.02]
LE_MoveIn Fixed Parts wave:le_value1 0.01 [-0.00, 0.01] -0.00 [-0.02, 0.01] -0.00 [-0.01, 0.00] -0.00 [-0.01, 0.01] -0.00 [-0.02, 0.01]
LE_NewPart Fixed Parts wave:le_value1 0.01 [0.01, 0.01] 0.01 [0.00, 0.02] 0.01 [-0.00, 0.02] 0.00 [-0.01, 0.02] -0.00 [-0.02, 0.01]
LE_ParDied Fixed Parts wave:le_value1 -0.00 [-0.01, 0.00] -0.00 [-0.01, 0.01] 0.01 [0.00, 0.01] -0.00 [-0.01, 0.00] 0.00 [-0.01, 0.01]
LE_PartDied Fixed Parts wave:le_value1 0.01 [-0.01, 0.02] 0.01 [-0.00, 0.02] 0.00 [-0.02, 0.01] -0.01 [-0.03, 0.01] 0.01 [0.01, 0.03]
LE_SepPart Fixed Parts wave:le_value1 0.01 [0.00, 0.02] 0.00 [-0.00, 0.01] 0.01 [0.01, 0.02] -0.02 [-0.04, -0.00] 0.01 [0.00, 0.01]

Random Effects

We often also want to plot random effects to look at individual level trajectories / variability. Again, we need to use the predict() function to get these values. You can also totally use matrix algebra if you’re like me and want to know what’s happening “under the hood.”
#### Categorical

ran_pred_fun <- function(fit){
tbl_df(fit@frame) %>% 
  mutate(pred = predict(fit, newdata = .))   
}
nested.mods <- nested.mods %>% 
  mutate(ran_pred1 = map(mod1, ran_pred_fun),
         ran_pred2 = map(mod2, ran_pred_fun)) 

sample_subs <- c(sample((dat_final %>% filter(LE_ChldBrth == 0))$PROC_SID, 100),
                 sample((dat_final %>% filter(LE_ChldBrth == 1))$PROC_SID, 100))

nested.mods %>% unnest(ran_pred2) %>%
  filter(PROC_SID %in% sample_subs) %>%
  ggplot(aes(x = wave, y = pred, group = PROC_SID, color = le_value)) +
    geom_line(size = .5, alpha = .5) +
    labs(x = "Year", y = "Predicted Personality Composite", 
         title = "Predicted Random Effect Trajectories") +
    facet_grid(Event ~ Trait) +
    theme_classic() +
    theme(axis.text = element_text(face = "bold", size = rel(1.2)),
          axis.title = element_text(face = "bold", size = rel(1.2)),
          legend.title = element_text(face = "bold", size = rel(1.2)),
          plot.title = element_text(face = "bold", size = rel(1.2), hjust = .5))

Continuous

sample_subs <- sample(unique(dat_final$PROC_SID), 200)

unconditional_model <- unconditional_model %>% 
  mutate(ran_pred1 = map(mod1, ran_pred_fun),
         ran_pred2 = map(mod2, ran_pred_fun)) 

unconditional_model %>% 
  unnest(ran_pred2) %>%
  filter(PROC_SID %in% sample_subs) %>%
  ggplot(aes(x = wave, y = pred, group = PROC_SID, color = Psych_LifeSat)) +
    geom_line(size = .5, alpha = .5) +
    labs(x = "Age", y = "Predicted Personality Composite", 
         title = "Predicted Random Effect Trajectories") +
    facet_wrap(~ Trait, nrow = 2) +
    theme_classic() +
    theme(axis.text = element_text(face = "bold", size = rel(1.2)),
          axis.title = element_text(face = "bold", size = rel(1.2)),
          legend.title = element_text(face = "bold", size = rel(1.2)),
          plot.title = element_text(face = "bold", size = rel(1.2), hjust = .5))